﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace ThreeByte.ActiveDeck.Data.UserResponse.Report {
    public class IndividualResponseData {

        protected static readonly XNamespace ns = Service.ServiceConfiguration.NAMESPACE;

        public List<IndividualUserData> UserDataElements {
            get;
            private set;
        }

        public string UserName { get; set; }

        public IndividualResponseData(string username) {
            UserName = username;
            UserDataElements = new List<IndividualUserData>();
        }

        public XElement ToXml() {
            XElement node = new XElement(ns + "User", new XAttribute("Name", UserName));

            foreach(IndividualUserData iud in UserDataElements) {
                node.Add(iud.ToXml());
            }

            return node;
        }

        public static IndividualResponseData ParseXml(XElement node) {
            IndividualResponseData individualResponseData = new IndividualResponseData(node.Attribute("Name").Value);
            foreach(XElement q in node.Elements()) {
                individualResponseData.UserDataElements.Add(IndividualUserData.ParseXml(q));
            }

            return individualResponseData;
        }
    }
}
